﻿<cfsilent>
	<cfscript>
		
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		
		keyword = trim(event.getArg('Keywords'));
		
		/* 搜索教师档案 */
		if ( len(keyword) ) {
			
			sql = "SELECT 
					tch_id, tch_name,  
					t_institute.institute_id, t_institute.institute_short 
					FROM t_teacher 
					INNER JOIN t_institute ON t_institute.institute_id = t_teacher.institute_id 
					WHERE 
						tch_name LIKE :keyword 
						OR 
						tch_id LIKE :keyword 
					ORDER BY 
						tch_name ASC ";
			
			queryObj = new Query( datasource=application.dnsSlave, maxRows=30 );
			queryObj.addParam( name="keyword", value=keyword & "%", cfsqltype="cf_sql_varchar" );
			
			rs_teacher = queryObj.execute( sql=sql ).getResult();
			
			teacherArray = [];
			
			for ( a=1; a LTE rs_teacher.recordCount; a++ ) {
				arrayAppend( teacherArray, [ rs_teacher["tch_id"][a], rs_teacher["tch_name"][a], rs_teacher["institute_id"][a], rs_teacher["institute_short"][a] ] );
			}
		}
		
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:teacherArray, stringNumbers:true)#</cfoutput>